package be.kuleuven.cs.mop.domain.model.impl;


import static org.junit.Assert.*;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import be.kuleuven.cs.mop.TestEnvironment;
import be.kuleuven.cs.mop.domain.exceptions.TaskManagerException;



public class ScheduleImplTest {
	
	private static TestEnvironment ENV;
	
	private static long			duration	= (15 * 60000L);
	private static Schedule schedule;
	
	
	
	@Before
	public void setUp() throws Exception {
		ENV = TestEnvironment.newInstance();
		
		schedule = new Schedule(ENV.datum1, ENV.datum2, duration);
	}
	
	@BeforeClass
	public static void setUpBeforeClass() throws Exception {}
	
	@After
	public void tearDown() throws Exception {}
	
	@AfterClass
	public static void tearDownAfterClass() throws Exception {}
	
	@Test(expected=TaskManagerException.class)
	public void testConstructorIllegalCase1() throws TaskManagerException{
		schedule = new Schedule(null, ENV.datum2, duration); 
	}
	
	@Test(expected=TaskManagerException.class)
	public void testConstructorIllegalCase2() throws TaskManagerException{
		schedule = new Schedule(ENV.datum1, null, duration); 
	}
	
	@Test(expected=TaskManagerException.class)
	public void testConstructorIllegalCase3() throws TaskManagerException{
		schedule = new Schedule(ENV.datum1, ENV.datum1, 0); 
	}
	
	@Test
	public void testConstructorLegalCase() throws TaskManagerException{
		schedule = new Schedule(ENV.datum1, ENV.datum2, duration);
		assertEquals(schedule.getStartDate(),	ENV.datum1);
		assertEquals(schedule.getDeadline(),	ENV.datum2);
		assertEquals(schedule.getDuration(),	duration);
	}
	
	@Test(expected=NullPointerException.class)
	public void testCoversIllegalCase() {
		assertTrue(schedule != null);
		assertTrue(schedule.covers(null));
	}
	
	@Test
	public void testCoversLegalCase(){
		assertTrue(schedule.covers(ENV.datum3));
	}
	
	@Test
	public void testValidation() {
		assertNotNull(schedule.toString());
		assertFalse(schedule.toString().isEmpty());
		assertFalse(Schedule.isValidSchedule(null, null, 0L));
		assertTrue(Schedule.isValidSchedule(
				ENV.datum1, ENV.datum2, ENV.duration));
		
//		assertNotNull(schedule.getEarliestEndTime(ENV.world.getTasks()));
//		assertNotNull(schedule.getEarliestEndTime(ENV.task1));
	}
	
}